﻿using System;
using System.Web.UI.WebControls;
using Bingosoft.Core;
using Bingosoft.Modules.SecurityConsole.Privilege;
using Bingosoft.Web.Utils;

namespace Bingosoft.WebApp.Modules.SecurityConsole.Privilege
{
    public partial class OperationList : System.Web.UI.BasePage
    {
        private PrivilegeService _privilegeService;
        private PrivilegeService PrivilegeService
        {
            get
            {
                return _privilegeService ??
                       (_privilegeService = App.Current.GetObjectContainer().GetObject("PrivilegeService") as PrivilegeService);
            }
        }

        protected void SearchGrid(object sender, EventArgs e)
        {
            this.GridSearch.Search();
        }

        protected void RefreshGrid(object sender, EventArgs e)
        {
            this.GridSearch.Refresh();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void DelOperations(object sender, EventArgs e)
        {
            String[] delOperations = SmartGridView1.GetCheckedValues();

            this.PrivilegeService.DeleteOperations(delOperations);

            this.GridSearch.Refresh();
            ScriptHelper.RegisterScript(this,"window.parent.reloadTree();");
        }

        protected void DelOperation(object sender, EventArgs e)
        {
            String operId = ((ImageButton)sender).Attributes["_KeyId"];

            this.PrivilegeService.DeleteOperation(operId);

            this.GridSearch.Refresh();
            ScriptHelper.RegisterScript(this,"window.parent.reloadTree();");
        }
    }
}